package com.hcbd.tdwt.ui.fuda.common.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;


import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.BaseActivity;

import com.hcbd.tdwt.base.bd.BdToolFactory;
import com.hcbd.tdwt.ui.xingyu.vo.BoxContact;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@SuppressLint("NonConstantResourceId")
@EActivity(R.layout.activity_add_contact_fuda)
public class AddContactActivity extends BaseActivity {
    //联系人名称
    @ViewById
    EditText addContactNameEdit;
    //联系人北斗卡
    @ViewById
    EditText addContactBoxCardIdEdit;
    //保存
    @ViewById
    Button saveBtn;
    @ViewById
    TextView title;
    @ViewById
    RelativeLayout topRL;
    private int entryMode = 0;
    private BoxContact boxContact;

    @AfterViews
    protected void init() {
        initData();
    }

    void initData() {
        title.setText("添加好友");
        if(BdToolFactory.app_type==BdToolFactory.HAI_GE_BG_TYPE){
            topRL.setBackground(ContextCompat.getDrawable(this,R.drawable.top_bg_haige));
            saveBtn.setText("添加并发新消息");
            saveBtn.setBackground(ContextCompat.getDrawable(this,R.drawable.button_blue_400_bg));
        }
        entryMode = getIntent().getIntExtra("entryMode", 0);
        if (entryMode == 1) {
            title.setText("编辑联系人");
            boxContact = (BoxContact) getIntent().getSerializableExtra("boxContact");
            if (boxContact == null) {
                toast("程序有误!");
                finish();
                return;
            }
            addContactNameEdit.setText(boxContact.getName());
            addContactBoxCardIdEdit.setText(boxContact.getBoxId());
        }
    }

    @Click
    void saveBtn() {
        String name = getTextStr(addContactNameEdit);
        String boxCardId = getTextStr(addContactBoxCardIdEdit);
        if (TextUtils.isEmpty(boxCardId)) {
            popupMsg("北斗卡号不能为空");
            return;
        }
        if (TextUtils.isEmpty(name)) {
            popupMsg("联系人名称不能为空");
            return;
        }
        if (entryMode == 1) {
            boxContact.setBoxId(boxCardId);
            boxContact.setName(name);
            boxContact.update();
        } else {
            BoxContact.upData(boxCardId, name, "已添加联系人，快发送消息吧", 0);
        }
        hideKeyboard();
        setResult(Activity.RESULT_OK);
        finish();
    }


    @Click
    void headLeft() {
        hideInputKeyBord();
        finish();
    }


}